#include <string.h>
-typedef struct {
+typedef struct
+{
const GtkBuildableParser *last_parser;
gpointer last_user_data;
int last_depth;
static void
pop_subparser_stack (GtkBuildableParseContext *context)
{
- GtkBuildableParserStack *stack =
- &g_array_index (context->subparser_stack, GtkBuildableParserStack,
- context->subparser_stack->len - 1);
+ GtkBuildableParserStack *stack = &g_array_index (context->subparser_stack, GtkBuildableParserStack,
+ context->subparser_stack->len - 1);
context->awaiting_pop = TRUE;
context->held_user_data = context->user_data;
static void
possibly_finish_subparser (GtkBuildableParseContext *context)
{
- if (context->subparser_stack->len > 0)
- {
- GtkBuildableParserStack *stack =
- &g_array_index (context->subparser_stack, GtkBuildableParserStack,
- context->subparser_stack->len - 1);
+ GtkBuildableParserStack *stack;
- if (stack->last_depth == context->tag_stack->len)
- pop_subparser_stack (context);
- }
+ if (!context->subparser_stack ||
+ context->subparser_stack->len == 0)
+ return;
+
+ stack = &g_array_index (context->subparser_stack, GtkBuildableParserStack,
+ context->subparser_stack->len - 1);
+
+ if (stack->last_depth == context->tag_stack->len)
+ pop_subparser_stack (context);
}
static void
/* report the error all the way up to free all the user-data */
+ if (!context->subparser_stack)
+ return;
+
while (context->subparser_stack->len > 0)
{
pop_subparser_stack (context);
context->parser = parser;
context->user_data = user_data;
- context->subparser_stack = g_array_new (FALSE, FALSE, sizeof (GtkBuildableParserStack));
+ context->subparser_stack = NULL;
context->tag_stack = g_ptr_array_new ();
context->held_user_data = NULL;
context->awaiting_pop = FALSE;
static void
gtk_buildable_parse_context_free (GtkBuildableParseContext *context)
{
- g_array_unref (context->subparser_stack);
+ if (context->subparser_stack)
+ g_array_unref (context->subparser_stack);
+
g_ptr_array_unref (context->tag_stack);
}
context->parser = parser;
context->user_data = user_data;
+ if (!context->subparser_stack)
+ context->subparser_stack = g_array_new (FALSE, FALSE, sizeof (GtkBuildableParserStack));
+
g_array_append_val (context->subparser_stack, stack);
}